/**
 * @projectName leetode
 * @package cn.leetcode
 * @className cn.leetcode.t589
 * @copyright Copyright 2020 Thunisoft, Inc All rights reserved.
 */
package cn.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * t589
 * @description
 * @author fei
 * @date 2025/9/8 16:38
 * @version 1.0
 */
public class t589 {
    public List<Integer> preorder(NodeN root) {
        List<Integer> ans = new ArrayList<>();
        dfs(root, ans);
        return ans;
    }
    public void dfs(NodeN root, List<Integer> ans){
        if (root == null){
            return;
        }
        ans.add(root.val);
        List<NodeN> children = root.children;
        for (int i = 0; i < children.size(); i++){
            if (children.get(i) != null){
                dfs(children.get(i), ans);
            }
        }
    }
}
class NodeN {
    public int val;
    public List<NodeN> children;

    public NodeN() {}

    public NodeN(int _val) {
        val = _val;
    }

    public NodeN(int _val, List<NodeN> _children) {
        val = _val;
        children = _children;
    }
};